import java.awt.MouseInfo;


public class MouseControl extends Thread {
	int winX,winY;
	Andreas text;
	private boolean go;
	int width, height, size;
	double[] coordinates;

	public MouseControl(Andreas text, int width, int height, int size){ 
		this.text=text;
		this.width=width;
		this.height=height;
		this.size=size;
		setPriority(2);
		go=false;
		coordinates = Robot.getCoordinates();
	}

	public void run() {
		while(true){
			while(go){

				int x = MouseInfo.getPointerInfo().getLocation().x-winX;
				int y = MouseInfo.getPointerInfo().getLocation().y-winY;
				
				double dist = Math.sqrt(Math.pow(x-width/2,2)+Math.pow(y-height/2, 2));
				if(dist<=size/2){
					

					double cX=((x-width/2)/(double) size)*160;
					double cY=((y-height/2)/(double) size)*160;
					coordinates[0] = cX;
					coordinates[2] = -cY;
					Robot.setCoordinates(coordinates);


					//System.out.println("("+MouseInfo.getPointerInfo().getLocation().x+", "+MouseInfo.getPointerInfo().getLocation().y+")" + " X: " + winX + " Y: "+ winY);
					//System.out.println("("+(MouseInfo.getPointerInfo().getLocation().x-winX)+", "+(MouseInfo.getPointerInfo().getLocation().y-winY)+")");
					text.printText("("+x+", "+y+")");
				}
				try {
					sleep(10);
				} catch (InterruptedException e) {
				}
			}

			try {
				sleep(100);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

	public void stopit(int x, int y){
		go=false;
		winX=x;
		winY=y;
	}
	public void startit(int x, int y){
		go=true;
		winX=x;
		winY=y;
	}
}